<template>
  <div>
    <h1>积分商城</h1>
    <table>
      <tr>
        <td>商品名称</td>
        <td>价格</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in data" :key="i">
        <td>{{ i.name }}</td>
        <td>{{ i.score }}</td>
        <td><button @click="duihuan(i.id)">兑换</button></td>
      </tr>
    </table>
  </div>

</template>

<script>
import axios from 'axios';

export default {
  name: "xiaoshangcheng"
  ,
  data() {
    return {
      data: '',
      userid:localStorage.getItem('userid')
    }
  },
  methods: {
    getdata() {
      axios({url: 'http://127.0.0.1:5000/getshangpin', method: 'get'}).then(res => {
        console.log(res)
        this.data = res.data.list
      })
    },
    duihuan(id){
      axios({url: 'http://127.0.0.1:5000/duihuan', method: 'post',data:{'userid':this.userid,'goodsid':id}}).then(res => {
        console.log(res)
        
      })
    }
  },
  mounted() {
    this.getdata()

  }
}
</script>

<style scoped>

</style>